<template>
  <el-select
      multiple
      clearable
      filterable
      placeholder="请选择审核员"
      class="ele-fluid"
      :value="value"
      @change="change">
    <el-option v-for="item in option" :key="item.id" :label="item.realname" :value="item.id"/>
  </el-select>
</template>

<script>
export default {
  props: {
    value: Array,
    unit: Number
  },
  model: {
    prop: 'value',
    event: 'change',
  },
  data: function () {
    return {
      option: [],
      loading: false,
    };
  },
  watch: {
    unit() {
      this.getData()
    },
    type() {
      this.getData()
    }
  },
  mounted() {
    this.getData()
  },
  methods: {
    getData() {
      this.loading = true
      this.$http.post('/user/index?page=1&limit=999&unit_id=' + this.unit).then(res => {
        if (res.data.code === 0) {
          this.option = res.data.data
        } else {
          this.$message.error(res.data.msg);
        }
        this.loading = false
      }).catch(e => {
        this.loading = false
        this.$message.error(e.message);
      });
    },
    change(val) {
      this.$emit('change', val);
    }
  },
};
</script>